package org.zmhhxl.api.auth.factory;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.zmhhxl.api.auth.RemoteThirdPartyService;
import org.zmhhxl.api.auth.domain.entity.ThirdPartyUser;
import org.zmhhxl.common.core.domain.Result;

import java.util.Optional;

/**
 * @Title: RemoteThirdPartyServiceFallbackFactory
 * @ProjectName: IntelliJ IDEA
 * @Description: TODO
 * @author: Administrator
 * @Date: 2024/10/21 0021上午 11:30
 */
@Slf4j
@Component
public class RemoteThirdPartyServiceFallbackFactory  implements FallbackFactory<RemoteThirdPartyService> {

   /**
    * Returns an instance of the fallback appropriate for the given cause.
    *
    * @param cause cause of an exception.
    * @return fallback
    */
   @Override public RemoteThirdPartyService create(Throwable cause) {
      log.error("调用api-user服务失败:{}", cause.getMessage());
      return new RemoteThirdPartyService(){

         @Override public Result<Optional<ThirdPartyUser>> findByThirdPartyIdAndThirdPartyDomain(String Id, String domain) {
            return Result.fail("服务失败fail:"+cause.getMessage());
         }

         @Override public Result<Optional<ThirdPartyUser>> findById(Long id) {
            return Result.fail("服务失败 by id fail:"+cause.getMessage());
            //return null;
         }

         @Override public Result<Optional<Long>> findUserIdById(Long Id) {
            return Result.fail("查找用户id服务失败 by id fail:"+cause.getMessage());
         }

         @Override public Result<Optional<ThirdPartyUser>> save(ThirdPartyUser thirdPartyUser) {
            return Result.fail("save用户id服务失败 by id fail:"+cause.getMessage());
         }

      };
   }
}
